package com.xiao.mall.foundation.errors;

import org.zalando.problem.AbstractThrowableProblem;
import org.zalando.problem.Status;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author tangzhihui
 * @Date 2021/11/26
 */
public class StoreResourceException extends AbstractThrowableProblem {

    private final String moduleName;
    private final String method;
    private final String productName;

    public StoreResourceException(String productName, String message, String moduleName, String method) {
        this(ErrorConstants.DEFAULT_TYPE, productName, message, moduleName, method);
    }

    public StoreResourceException(URI type, String productName, String message, String moduleName, String method) {
        super(type, message, Status.BAD_REQUEST, null, null, null, getAlertParameters(moduleName, method, productName));
        this.method = method;
        this.productName = productName;
        this.moduleName = moduleName;
    }

    private static Map<String, Object> getAlertParameters(String entityName, String method, String productName) {
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("message", String.format("method:%s,product:%s, error", method, productName));
        parameters.put("params", entityName);
        return parameters;
    }
}
